<!-- 添加银行卡 -->
<template>
    <div class=''>

        <el-form ref="form" :model="formInline" label-width="100px" class="custom-form" :rules="rules">
            <el-form-item label="姓名" prop="name">
                <el-input class="custom-input" type="text" v-model="formInline.name" placeholder="">
                </el-input>
            </el-form-item>
            <el-form-item label="卡号" prop="bank_number">
                <el-input class="custom-input" type="text" v-model="formInline.bank_number" placeholder="">
                </el-input>
            </el-form-item>
            <el-form-item label="开户行名称" prop="bank_name">
                <el-input class="custom-input" type="text" v-model="formInline.bank_name" placeholder="">
                </el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="sureAdd">确认添加</el-button>
            </el-form-item>
        </el-form>

    </div>
</template>

<script>
import { addBankAccount } from '@/api/moneyManagment'
export default {
    //import引入的组件需要注入到对象中才能使用
    components: {},
    data() {
        //这里存放数据
        return {
            formInline: {
                name: '',
                bank_number: '',
                bank_name: '',
            },
            rules: {
                name: { required: true, message: '请输入姓名', trigger: 'change' },
                bank_number: { required: true, message: '请输入卡号', trigger: 'change' },
                bank_name: { required: true, message: '请输入开户行名称', trigger: 'change' },
            },
        };
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods: {
        async sureAdd() {
            this.$refs['form'].validate(async (valid) => {
                if (valid) {
                    const loading = this.$loading({
                        lock: true,
                        text: '请求中...',
                        spinner: 'el-icon-loading',
                        background: 'rgba(0, 0, 0, 0.7)',
                    });
                    let res = await addBankAccount(this.formInline);
                    loading.close();
                    if (res.code == 200) {
                        this.$message.success(res.msg)
                    } else {
                        this.$message.error(res.msg)
                    }
                    this.$emit('closeDialog')
                } else {
                    return false;
                }
            });
        }
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {

    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {

    },
    beforeCreate() { }, //生命周期 - 创建之前
    beforeMount() { }, //生命周期 - 挂载之前
    beforeUpdate() { }, //生命周期 - 更新之前
    updated() { }, //生命周期 - 更新之后
    beforeDestroy() { }, //生命周期 - 销毁之前
    destroyed() { }, //生命周期 - 销毁完成
    activated() { }, //如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
.custom-form {
    margin: 20px 25% 20px 25%;

    ::v-deep .el-form-item__label {
        font-size: 15px;
        font-weight: 600;
    }

    ::v-deep .pwd-input {
        .el-input__inner[type="password"] {
            letter-spacing: 10px;
        }
    }
}
</style>